package com.kly.chatter.db.dao.impl;
import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.google.common.collect.Maps;
import com.kly.chatter.db.dao.ChatterModelInfoExamineDao;
import com.kly.chatter.db.entity.ChatterModelInfoExamineEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* User: a
* Date: 2023-10-07
* Time: 15:45:35.003
*/

@Repository
public class ChatterModelInfoExamineDaoImpl extends AbstractBaseMapper<ChatterModelInfoExamineEntity> implements ChatterModelInfoExamineDao {

    @Override
    public ChatterModelInfoExamineEntity getLastRecord(String userCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        return getSqlSession().selectOne(this.getStatement("getLastRecord"), params);
    }

    @Override
    public List<ChatterModelInfoExamineEntity> listProfileAudit(List<String> modelUserCodes, String modelUserCode, Integer approvalStatus, Page page) {
        final HashMap<String, Object> params = setUpParams(modelUserCodes, modelUserCode, approvalStatus, page);
        return this.getSqlSession().selectList(this.getStatement("listProfileAudit"), params);
    }

    @Override
    public int getProfileAuditCnt(List<String> modelUserCodes, String modelUserCode, Integer approvalStatus) {
        final HashMap<String, Object> params = setUpParams(modelUserCodes, modelUserCode, approvalStatus, null);
        return this.getSqlSession().selectOne(this.getStatement("getProfileAuditCnt"), params);

    }

    @Override
    public ChatterModelInfoExamineEntity getById(Integer id) {
        return this.getSqlSession().selectOne(this.getStatement("getById"), id);
    }

    private HashMap<String, Object> setUpParams(List<String> modelUserCodes, String modelUserCode, Integer approvalStatus, Page page) {
        final HashMap<String, Object> params = Maps.newHashMap();
        if (CollectionUtils.isNotEmpty(modelUserCodes)) {
            params.put("modelUserCodes", modelUserCodes);
        }
        if (StringUtils.isNotBlank(modelUserCode)) {
            params.put("modelUserCode", modelUserCode);
        }
        if (approvalStatus != null && approvalStatus != 99) {
            params.put("approvalStatus", approvalStatus);
        }
        if (page != null) {
            params.put("page", page);
        }
        return params;
    }

    @Override
    public int approval(Integer id, Integer approvalStatus, String dealUserCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("id", id);
        params.put("approvalStatus", approvalStatus);
        params.put("dealUserCode", dealUserCode);
        params.put("dealTime", new Date());
        return this.getSqlSession().update(this.getStatement(".approval"), params);
    }
}